package com.trace.app.controller;


import com.trace.app.entity.ResponseResult;
import com.trace.app.entity.Star;
import com.trace.app.service.StarService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Star)表控制层
 *
 * @author lionkliu
 * @since 2024-04-22 09:44:21
 */
@RestController
@RequestMapping("star")
public class StarController {

    @Resource
    private StarService starService;

    @GetMapping("/page")
    public ResponseResult selectPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize) {
        return starService.selectPage(pageNum, pageSize);
    }

    @GetMapping("/list")
    public ResponseResult list() {
        return ResponseResult.okResult(starService.list());
    }

    @GetMapping("/check")
    public ResponseResult selectOne(@RequestParam("userId") Integer userId,
                                    @RequestParam("proId") Integer proId) {
        return starService.selectOne(userId, proId);
    }

    @GetMapping("{userId}")
    public ResponseResult getStarsByUserId(@PathVariable("userId") Integer userId) {
        return starService.getStarsByUserId(userId);
    }

    @PostMapping
    public ResponseResult insert(@RequestBody Star star) {
        return starService.insertOne(star);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Star star) {
        return starService.updateOne(star);
    }

    // 通过唯一索引删除 (userId,proId)
    @DeleteMapping
    public ResponseResult delete(@RequestBody Star star) {
        return starService.delete(star.getUserId(), star.getProId());
    }

}
